//
// Created by vcq on 21/2/9.
//
#pragma once

#include "dbng.hpp"

struct finishrequire {
    int id;
    string name;
    string note;
    int _plan_id;
};
REFLECTION(finishrequire, id, name, _plan_id,note)

json m_getFinishRequire(basic_string_view<char> id, basic_string_view<char> _plan_id) {
    string sql = "select * from `finishrequire` where 1=1 ";
    if (!id.empty()) {
        sql += "and id =";
        sql += id;
    }
    if (!_plan_id.empty()) {
        sql += "and _plan_id =";
        sql += _plan_id;
    }
    Dao dao;
    auto v = dao.query<finishrequire>(sql);
    nlohmann::json article_list,ret,item;
    for (auto &o : v) {
        item["id"] = o.id;
        item["name"] = o.name;
        item["note"] = o.note;
        item["_plan_id"] = o._plan_id;
        article_list.push_back(item);
    }
    ret["code"] = 0;
    ret["count"] = article_list.size();
    ret["data"] = article_list;
    return ret;
}

void MAddFinishRequire(const struct finishrequire& finishrequire1){
    Dao dao;
    dao.update_object(finishrequire1);
}
void MDeleteFinishRequire(basic_string_view<char> id){
    MDeleteAll("finishrequire",id);
}